#include <iostream>
#include <string>
#include "Log.hpp"
#include "Listener.hpp"
#include "Connection.hpp"
#include "Reactor.hpp"

using namespace LogModule;
 
// 专门负责获取链接的模块
// 连接管理器

// ./epollserver serverport
int main(int argc, char* argv[])
{
    ENABLE_CONSOLE_LOG();

    if (argc!= 2) {
        std::cout << "Usage:./epollserver serverport" << std::endl;
        return 1;
    }
    uint16_t serverPort = std::atoi(argv[1]);

    auto conn = std::make_shared<Listener>(serverPort);
    // 完成具体工作的模块
    //Listener listen(serverPort);  

    // 我们吧listensockfd封装成一个Connection，把他托管为EpollServer
    // auto conn = std::make_shared<Connection>(listen.Sockfd());
    // func_t f = std::bind(Listener::Accepter, &listen, conn, nullptr);
    // conn->InitCB(f, nullptr,nullptr);

    // auto conn1 = Factory::BuildConnection(listen.Sockfd(), EPOLLIN | EPOLLET, [&listen](){
    //     listen.Accepter();
    // }
    // ,nullptr,nullptr);

    Reactor epoll_svr;
    epoll_svr.InsertConnection(conn);
    epoll_svr.Loop();

    return 0;
}